package com.shangrila.biz.category;

import java.util.List;

import org.apache.commons.collections.CollectionUtils;

public class CategoryDO {

	/**类目id*/
	private long catId;
	/**类目名称*/
	private String name;
	/**对应淘宝前台类目id*/
	private long taobaoCatId;
	/**父类目id*/
	private long parentCatId;
	/**默认展示的宝贝数量，仅供参考*/
	private int displayCount;
	/**当前类目所处的类目级别*/
	private CategoryLevel categoryLevel;
	/**父类目对象*/
	private CategoryDO parent;
	/**子类目列表*/
	private List<CategoryDO> child;
	/**默认的二级类目id，当且仅当类目为一级类目的时候才有该值*/
	private long defaultLevel2CatId;
	/**默认类目下的关键字，可能为空*/
	private String q;
	/**
	 * 是否是一级类目
	 */
	public boolean isLevel1Category(){
		return categoryLevel == CategoryLevel.Level1;
	}
	/**
	 * 是否是二级类目
	 */
	public boolean isLevel2Category(){
		return categoryLevel == CategoryLevel.Level2;
	}
	/**是否有子节点*/
	public boolean hasChild(){
		return CollectionUtils.isNotEmpty(getChild());
	}
	@Override
	public String toString() {
		StringBuilder sb = new StringBuilder();
		sb.append(toString(this)).append(",parent=[").append(toString(getParent())).append("]");
		if(CollectionUtils.isNotEmpty(getChild())){
			sb.append(",child=[");
			for(CategoryDO categoryDO : getChild()){
				sb.append(toString(categoryDO)).append(",");
			}
			return new StringBuilder().append(sb.substring(0,sb.length() -1)).append("]").toString();
		}
		return sb.toString();
	}
	
	private String toString(CategoryDO categoryDO){
		if(categoryDO == null)return "";
		StringBuilder sb = new StringBuilder();
		sb.append("catId=").append(categoryDO.getCatId()).append(",catName=").append(categoryDO.getName()).append(",level=").append(categoryDO.getCategoryLevel().toString()).append(",displayCount=").append(categoryDO.getDisplayCount()).append(",taobaoCatId=").append(categoryDO.getTaobaoCatId());
		return sb.toString();
	}

	public long getCatId() {
		return catId;
	}

	public void setCatId(long catId) {
		this.catId = catId;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getTaobaoCatId() {
		return taobaoCatId;
	}

	public void setTaobaoCatId(long taobaoCatId) {
		this.taobaoCatId = taobaoCatId;
	}

	public long getParentCatId() {
		return parentCatId;
	}

	public void setParentCatId(long parentCatId) {
		this.parentCatId = parentCatId;
	}

	public int getDisplayCount() {
		return displayCount;
	}

	public void setDisplayCount(int displayCount) {
		this.displayCount = displayCount;
	}
	public CategoryLevel getCategoryLevel() {
		return categoryLevel;
	}
	public void setCategoryLevel(CategoryLevel categoryLevel) {
		this.categoryLevel = categoryLevel;
	}
	public CategoryDO getParent() {
		return parent;
	}

	public void setParent(CategoryDO parent) {
		this.parent = parent;
	}

	public List<CategoryDO> getChild() {
		return child;
	}

	public void setChild(List<CategoryDO> child) {
		this.child = child;
	}
	public long getDefaultLevel2CatId() {
		return defaultLevel2CatId;
	}
	public void setDefaultLevel2CatId(long defaultLevel2CatId) {
		this.defaultLevel2CatId = defaultLevel2CatId;
	}
	public String getQ() {
		return q;
	}
	public void setQ(String q) {
		this.q = q;
	}
}
